import {
  IsBoolean,
  IsNumber,
  IsOptional,
  IsString,
  Length,
  MaxLength,
  MinLength
} from 'class-validator';
import { applyDecorators } from '@nestjs/common';
import { IsUsernameUnique, StartWith } from '../validators/user-validator';
import { ApiProperty, ApiPropertyOptional, PartialType } from '@nestjs/swagger';

function PasswordValidators() {
  return applyDecorators(IsString(),MinLength(6),MaxLength(8))
}

function MobileValidators() {
  return applyDecorators(IsString(),Length(11),)
}



export class CreateUserDto {
  @IsString()
  @StartWith('user_')
  // @Validate(StartsWithConstraint)
  @IsUsernameUnique()
    @ApiProperty({description:'用户名',example:'user_123'})
  username: string;
  @PasswordValidators()
  @ApiProperty({description:'密码',example:'123456'})
  password: string;
  @MobileValidators()
  @ApiProperty({description:'手机号',example:'12345678901'})
  @ApiPropertyOptional()
  mobile: string;
  @IsString()
  @ApiProperty({description:'邮箱',example:'12345678901@qq.com'})
  email: string;
  @IsNumber()
  @ApiProperty({description:'状态',example:'1'})
  status: number;
  @IsBoolean()
  @IsOptional()
  @ApiProperty({description:'是否是超级管理员',example:'true'})
  isSuper: boolean;
  @IsNumber()
  @ApiProperty({description:'排序',example:'1'})
  sort: number;
}

export class UpdateUserDto extends PartialType(CreateUserDto) {
  @ApiProperty({description:'id',example:'1'})
  id: number;
}


